package com.banggood.upms.bean.vo;

import com.banggood.upms.bean.vo.validation.AddGroup;
import com.banggood.upms.bean.vo.validation.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author XuChuangFeng
 */
@Data
@ApiModel(value = "树对象", description = "负责接收封装调用者传入的参数")
public class TreeVo implements Serializable {

    @NotNull(message = "{validation.NotNull.id}", groups = {UpdateGroup.class})
    @Null(message = "{validation.Null.id}", groups = {AddGroup.class})
    private String treeId;

    private String parentId;

    @ApiModelProperty(value = "节点码", required = true)
    @NotNull(message = "{validation.TreeVo.nodeCode.NotNull}", groups = {AddGroup.class})
    private String nodeCode;

    @ApiModelProperty(value = "节点名称", required = true)
    @NotNull(message = "{validation.TreeVo.nodeName.NotNull}", groups = {AddGroup.class})
    private String nodeName;

    @ApiModelProperty(value = "树分组")
    private String treeGroup;

    @ApiModelProperty(value = "备注")
    private String remark;

    private String path;

    @NotNull(message = "{validation.TreeVo.treeType.NotNull}", groups = {AddGroup.class})
    private String treeType;

    private TreeVo parentNodeVo;

    private List<String> subTreeIds;

    private List<TreeVo> subTreeList;

    public void addSubTree(TreeVo vo) {
        if(CollectionUtils.isEmpty(this.subTreeList)) {
            this.subTreeList = new ArrayList<>();
        }
        this.subTreeList.add(vo);
    }

    public void addSubTreeId(String subTreeId) {
        if(this.subTreeIds == null) {
            this.subTreeIds = new ArrayList<>();
        }
        this.subTreeIds.add(subTreeId);
    }
}